<%--
  Created by IntelliJ IDEA.
  User: 33737
  Date: 2019/1/4
  Time: 20:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        table tr:nth-child(2n){
            background-color: #ccf6ce
        }
    </style>

    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.11.0.js"></script>
    <script type="text/javascript">

        function editEbook(id){
//            var title=$("input[name='title"+id+"']");
            var title=$("#title"+id).val();
            var summary=$("#summary"+id).val();
            var uploaduser=$("#uploaduser"+id).val();
            $.ajax({
                url:"${pageContext.request.contextPath}/ebook/edit",
                data:{id:id,title:title,summary:summary,uploaduser:uploaduser},
                dataType:"text",
                type:"POST",
                success:function(result){
                    if(result=='1'){
                        alert("更新数据成功！");
                    }else{
                        alert("更新数据失败！");
                    }
                    window.location=window.location;
                },
                error:function(){
                    alert("对不起！服务器正忙!");
                    window.location=window.location;
                }
            });
        }


        function jumpsave(){
            window.location.href="${pageContext.request.contextPath}/ebook/save";
        }

        function deleteEbook(id) {

            if(!confirm("数据删除就无法恢复，确定要删吗!")){
                return;
            }

            $.get("/ebook/dodelete",{id:id},function (result) {
                if (result=="1"){
                    alert("删除成功");
                }else {
                    alert("删除失败");
                }
                window.location=window.location;
            });

        }

        $(function () {
            $("#cbAll").click(function () {
                $("input[name='cbItem']").prop("checked", $("#cbAll").prop("checked"));
            });
        });
        function deleteAllEbooks () {
            if (!confirm("数据删除就无法恢复，确定要删吗!")){
                return ;
            }
            var ids ="-1";
            $("input[name='cbItem']").each(function () {
                if(this.checked){
                    var id= $(this).val();
                    ids+=","+id;
                }
            });
            $.get("${pageContext.request.contextPath }/ebook/dodeleteall",{ids:ids},function (result) {
                if(result=="1"){
                    alert("批量删除成功");
                }else {
                    alert("批量删除失败");
                }
                window.location= window.location;
            });
        }
    </script>

</head>
<body>
<form action="${pageContext.request.contextPath}/ebook/list" method="post">
    <table border="1" width="805">
        <tr><td colspan ="6" align="center" style="font-size:30px">电子图书列表</td></tr>
        <tr>
            <td>图书标题:<input type="text" name="title" value="${ebook.title}"/></td>
            <td>图书分类：<select name="categoryId">
                <option value="0">==不限==</option>
                <c:forEach var="item" items="${plist}">
                    <option <c:if test="${item.id==ebook.categoryId}">selected="selected"</c:if> value="${item.id}">${item.typeName}</option>
                </c:forEach>
            </select>
                <input type="submit" value="查询">
            </td>
            <td><input type="button" value="新增电子书" onclick=javascript:jumpsave() /></td>
            <td><input type="button" value="批量删除" onclick=javascript:deleteAllEbooks() /></td>
        </tr>
    </table>
</form>

<table border="1" width="805">
    <tr>
        <td><input type="checkbox" id="cbAll"/></td>
        <td>图书编号</td>
        <td>图书名称</td>
        <td>图书摘要</td>
        <td>上传人</td>
        <td>上传时间</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${list}" var="li">
        <tr>
            <td><input type="checkbox" name="cbItem" value="${li.id}"/></td>
            <td>${li.id}</td>
            <td><input type="text" id="title${li.id}" name="title${li.id}" value="${li.title}"/></td>
            <td><input type="text" id="summary${li.id}" name="title${li.id}" value="${li.summary}"/></td>
            <td><input type="text" id="uploaduser${li.id}" name="title${li.id}" value="${li.uploaduser}"/></td>
            <td><fmt:formatDate value="${li.createDate}" pattern="yyyy-MM-dd HH:mm"/></td>
            <td>
                <a href="javascript:void(0)" onclick="editEbook(${li.id});">更新</a>
                <a href="${pageContext.request.contextPath}/ebook/update?id=${li.id}">修改</a>
                <a href="javascript:void(0)" onclick="deleteEbook(${li.id});">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
<p>共${pageTool.totalRecordCount}条数据，当前第 ${pageTool.currPageNo}/${pageTool.pageCount}页,每页${pageTool.pageSize}条

    <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=1">首页</a>
    <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=${pageTool.currPageNo-1}">上一页</a>

    <c:forEach var="prePage" items="${prePages}">
        <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=${prePage}">${prePage}</a>

    </c:forEach>
    <b >${pageTool.currPageNo}</b>
    <c:forEach var="nextPage" items="${nextPages}">
        <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=${nextPage}">${nextPage}</a>

    </c:forEach>

    <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=${pageTool.currPageNo+1}">下一页</a>
    <a href="${pageContext.request.contextPath}/ebook/list?title=${ebook.title}&categoryId=${ebook.categoryId}&currPageNo=${pageTool.pageCount}">末页</a>

</p>
</body>
</html>
